/**
 * 
 */
package com.fish.user.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fish.common.constant.QueryPage;
import com.fish.common.dao.BaseIbatisDao;
import com.fish.common.tag.Pager;
import com.fish.sight.po.Sight;
import com.fish.user.po.User;

/**
 * @author damian
 *
 */
public class UserDao extends BaseIbatisDao {
	@SuppressWarnings("unchecked")
	public Pager<User> selectUserWithPaging(Map<String,Object> param){
//		if(param!=null && param.get("postTimeEnd")!=null && !"".equals(param.get("postTimeEnd"))){
//			param.put("postTimeEnd", String.valueOf(param.get("postTimeEnd"))+" 23:59:59");
//		}
//		if(param!=null && param.get("updateTimeEnd")!=null && !"".equals(param.get("updateTimeEnd"))){
//			param.put("updateTimeEnd", String.valueOf(param.get("updateTimeEnd"))+" 23:59:59");
//		}
		Long count = 0L;
		Pager<User> pager = new Pager<User>();
		List<User> list=this.getSqlMapClientTemplate().queryForList("USER.selectUserWithPaging",param);
		count=(Long)this.getSqlMapClientTemplate().queryForObject("USER.countUserWithPaging",param);
		pager.setData(list);
		pager.setCount(count.intValue());
		return pager;
	}
	
	public Long insertUser(User obj){
		return (Long)this.getSqlMapClientTemplate().insert("USER.insertUser", obj);
	}
	
	public User selectUserById(String id){
		return (User)this.getSqlMapClientTemplate().queryForObject("USER.selectUserById", id);
	}
	
	public boolean updateUser(User obj){
		int changedCount=this.getSqlMapClientTemplate().update("USER.updateUser", obj);
		if(changedCount>0){
			return true;
		}
		return false;
	}
	
	public boolean deleteUser(String id,String updateUserId){
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("userId", id);
		param.put("updateUserId", updateUserId);
		int changedCount=this.getSqlMapClientTemplate().delete("USER.deleteUser", param);
		if(changedCount>0){
			return true;
		}
		return false;
	}
	
	public Long queryUserCountByObject(User user){
		return  (Long) this.getSqlMapClientTemplate().queryForObject("USER.countUserWithPaging", user);
	}
	
	public  List<User> queryUserByObject(User user,QueryPage queryPage){
		user.setBeginItem(queryPage.getBeginItem());
		user.setEndItem(queryPage.getPageSize());
		return (List<User>) this.getSqlMapClientTemplate().queryForList("USER.selectUserWithPaging", user);
	}

	public User getUserByUser(User user) {
		return (User)this.getSqlMapClientTemplate().queryForObject("USER.selectByUser", user);
	}
}
